<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>40-本地存储复杂类型数据</title>
  </head>
  <body>
    <script>
      const goods = {
        name: '小米',
        price: 1999
      }
    //   localStorage.setItem('goods',goods)
    //   console.log(localStorage.getItem('goods'))

    //   1.把对象转换为JSON字符串  语法：JSON.stringify(复杂数据类型)
      localStorage.setItem('goods',JSON.stringify(goods))
      console.log(localStorage.getItem('goods'))
    //   console.log(typeof localStorage.getItem('goods'))

    // 2. 把JSON字符串转换为对象  语法：JSON.parse(JSON字符串)
    console.log(JSON.parse(localStorage.getItem('goods')))
    
      
      
    </script>
  </body>
</html>
